//
//  ConAdderViewController.m
//  Shengzhuli
//
//  Created by FXGuo on 2017/7/12.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "ConAdderViewController.h"
#import "AdderHeaderCell.h"
#import "AdderBecomeInCell.h"
#import "ConVipViewViewController.h"
#import "SZLAccountHelper.h"
#import "ConAlreadyAdderViewController.h"
#import "ImageCell.h"
#import "ConVipViewViewController.h"
#import "ConVipViewController.h"
#import "GGIndicatorHud.h"

@interface ConAdderViewController ()<UIWebViewDelegate>

@property (nonatomic, strong) UIWebView *webView;
@property (nonatomic, strong) UIButton *virifyButton;
@end

@implementation ConAdderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
//    self.view.backgroundColor = RGBColor(31, 102, 255);
//    [self setUpTableView];
    [self createWebView];
    [self createButton];
}
- (void)createButton {
    
    _virifyButton=  [UIButton buttonWithType:(UIButtonTypeCustom)];
    _virifyButton.frame = CGRectMake(ScreenW-80, ScreenH/2-64-40, 80, 80);
    _virifyButton.layer.cornerRadius = 40;
    
    [_virifyButton setTitle:@"立即加入" forState:(UIControlStateNormal)];
    [_virifyButton setBackgroundColor:RGBColor(31, 102, 255)];
    [_virifyButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    _virifyButton.titleLabel.font = [UIFont systemFontOfSize:14];
    
    [_virifyButton addTarget:self action:@selector(goToVirify) forControlEvents:(UIControlEventTouchUpInside)];
    [_webView addSubview:_virifyButton];
}

- (void)goToVirify {
 
    if ([SZLAccountHelper shareInstance].roleId ==2) {
        
        ConAlreadyAdderViewController *cvc = [[ConAlreadyAdderViewController alloc] init];
        [self.navigationController pushViewController:cvc animated:YES];
    }else if([SZLAccountHelper shareInstance].roleId ==3){
        ConVipViewViewController *ccvc = [[ConVipViewViewController alloc] init];
        ccvc.type = 2;
        [self.navigationController pushViewController:ccvc animated:YES];
    }else {
        ConVipViewViewController *ccvc = [[ConVipViewViewController alloc] init];
        //ccvc.type = 2;
        [self.navigationController pushViewController:ccvc animated:YES];
    }
}
- (void) createWebView{
    
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH-64-44-40)];
    NSString *urlString = [PublicServer stringByAppendingString:@"/partner/introduce"];
    _webView.backgroundColor = [UIColor whiteColor];
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [self.view addSubview:_webView];
    [GGIndicatorHud showIndicatorInView:_webView];
    [_webView loadRequest:request];
    [GGIndicatorHud hideIndicatorHudInView:_webView];

}
/*
- (void)setUpTableView
{
    self.tableView.tableFooterView = [[UIView alloc]init];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ImageCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([ImageCell class])];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([AdderHeaderCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([AdderHeaderCell class])];
    self.tableView.tableFooterView = [[UIView alloc]init];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([AdderBecomeInCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([AdderBecomeInCell class])];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5+3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row<=4) {
        return ScreenW*800/1440;
    }else if (indexPath.row == 5) {
        return 100;
    }
    return 260;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row<=4) {
        ImageCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ImageCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.imageName = [NSString stringWithFormat:@"%zd",indexPath.row+1];
        return cell;
    }else if (indexPath.row == 5) {
        AdderHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([AdderHeaderCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    AdderBecomeInCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([AdderBecomeInCell class])];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 7) {
        cell.imageName = @"体验式";
        cell.nameStr = @"还在为产品没有出路而烦恼？加入我们吧";
        cell.subNameStr = @"只要你的产品够好，最好的客户都在这里";
        cell.btnTag = indexPath.row;
    }
    cell.btnClickBlock = ^(NSInteger btnTag) {
        if ([SZLAccountHelper shouldLogin]) return ;
        if ([SZLAccountHelper shareInstance].roleId == 2) {
            ConAlreadyAdderViewController *adderVc = [[ConAlreadyAdderViewController alloc]init];
            [self.navigationController pushViewController:adderVc animated:YES];
            return;
        }
        ConVipViewViewController *vipVc = [[ConVipViewViewController alloc]init];
        vipVc.type = 3;
        if (btnTag == 1) {
            vipVc.type = 2;
        }
        [self.navigationController pushViewController:vipVc animated:YES];
    };
    return cell;
}
*/
@end
